﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.Entity;
using FlatOut.Dal.Domain;

namespace FlatOut.Dal.Context
{
    // context
    public class FlatOutContext : DbContext
    {
        // entities
        public DbSet<User> Users { get; set; }
        public DbSet<Group> Groups { get; set; }
        public DbSet<Circuit> Circuits { get; set; }
        public DbSet<Score> Scores { get; set; }
        public DbSet<Car> Cars { get; set; }
    }

    // initialisation de la base
    public class FlatOutInitializer : CreateDatabaseIfNotExists<FlatOutContext>
    {
        protected override void Seed(FlatOutContext context)
        {
            base.Seed(context);

            User[] users = {
                new User { Nickname = "Ben" },
                new User { Nickname = "Chris" },
                new User { Nickname = "Ced" }
            };
            foreach (User user in users) context.Users.Add(user);


            Group[] groups = {
                new Group() { Id = 1, Name = "Canal", Type = GroupType.Circuit },
                new Group() { Id = 2, Name = "City Central", Type = GroupType.Circuit },
                new Group() { Id = 3, Name = "Desert", Type = GroupType.Circuit },
                new Group() { Id = 4, Name = "Downtown", Type = GroupType.Circuit },
                new Group() { Id = 5, Name = "Farmlands", Type = GroupType.Circuit },
                new Group() { Id = 6, Name = "Motor Raceway", Type = GroupType.Circuit },
                new Group() { Id = 7, Name = "Pinegrove", Type = GroupType.Circuit },
                new Group() { Id = 8, Name = "Ranch", Type = GroupType.Circuit },
                new Group() { Id = 9, Name = "Riverbay", Type = GroupType.Circuit },
                new Group() { Id = 10, Name = "Special", Type = GroupType.Circuit },
                new Group() { Id = 11, Name = "Timberlands", Type = GroupType.Circuit }
            };
            foreach (Group group in groups) context.Groups.Add(group);


            Circuit[] circuits = {
                new Circuit() { Id = 1, Name = "Canal 1", Group = groups[0] },
                new Circuit() { Id = 2, Name = "Canal 2", Group = groups[0] },
                new Circuit() { Id = 3, Name = "Canal 3", Group = groups[0] },
                new Circuit() { Id = 4, Name = "City Central 1", Group = groups[1] },
                new Circuit() { Id = 5, Name = "City Central 2", Group = groups[1] },
                new Circuit() { Id = 6, Name = "City Central 3", Group = groups[1] },
                new Circuit() { Id = 7, Name = "Desert Oil Field", Group = groups[2] },
                new Circuit() { Id = 8, Name = "Desert Scrap Yard", Group = groups[2] },
                new Circuit() { Id = 9, Name = "Desert Town", Group = groups[2] },
                new Circuit() { Id = 10, Name = "Downtown 1", Group = groups[3] },
                new Circuit() { Id = 11, Name = "Downtown 2", Group = groups[3] },
                new Circuit() { Id = 12, Name = "Downtown 3", Group = groups[3] },
                new Circuit() { Id = 13, Name = "Farmland 1", Group = groups[4] },
                new Circuit() { Id = 14, Name = "Farmland 2", Group = groups[4] },
                new Circuit() { Id = 15, Name = "Farmland 3", Group = groups[4] },
                new Circuit() { Id = 16, Name = "Motor Raceway 1", Group = groups[5] },
                new Circuit() { Id = 17, Name = "Motor Raceway 2", Group = groups[5] },
                new Circuit() { Id = 18, Name = "Motor Raceway 3", Group = groups[5] },
                new Circuit() { Id = 19, Name = "Pinegrove 1", Group = groups[6] },
                new Circuit() { Id = 20, Name = "Pinegrove 2", Group = groups[6] },
                new Circuit() { Id = 21, Name = "Pinegrove 3", Group = groups[6] },
                new Circuit() { Id = 22, Name = "Ranch 1", Group = groups[7] },
                new Circuit() { Id = 23, Name = "Ranch 2", Group = groups[7] },
                new Circuit() { Id = 24, Name = "Ranch 3", Group = groups[7] },
                new Circuit() { Id = 25, Name = "Riverbay Circuit 1", Group = groups[8] },
                new Circuit() { Id = 26, Name = "Riverbay Circuit 2", Group = groups[8] },
                new Circuit() { Id = 27, Name = "Riverbay Circuit 3", Group = groups[8] },
                new Circuit() { Id = 28, Name = "Speedway Left", Group = groups[9] },
                new Circuit() { Id = 29, Name = "Speedway Right", Group = groups[9] },
                new Circuit() { Id = 30, Name = "Speedway Special", Group = groups[9] },
                new Circuit() { Id = 31, Name = "Sand Sandway", Group = groups[9] },
                new Circuit() { Id = 32, Name = "Speedbowl", Group = groups[9] },
                new Circuit() { Id = 33, Name = "Triloop Special", Group = groups[9] },
                new Circuit() { Id = 34, Name = "Figure of Eight 1", Group = groups[9] },
                new Circuit() { Id = 35, Name = "Figure of Eight 2", Group = groups[9] },
                new Circuit() { Id = 36, Name = "Timberland 1", Group = groups[10] },
                new Circuit() { Id = 37, Name = "Timberland 2", Group = groups[10] },
                new Circuit() { Id = 38, Name = "Timberland 3", Group = groups[10] },             
            };
            foreach (Circuit circuit in circuits) context.Circuits.Add(circuit);

            Car[] cars = {
                new Car() { Id = 1, Name = "Vexter XS" },
                new Car() { Id = 2, Name = "Bullet GT" },
                new Car() { Id = 3, Name = "CTR Sport" },
                new Car() { Id = 4, Name = "Rocket" },
                new Car() { Id = 5, Name = "Sunray" },
                new Car() { Id = 6, Name = "Chili Pepper" },
                new Car() { Id = 7, Name = "Insetta" },
                new Car() { Id = 8, Name = "Scorpion" },
                new Car() { Id = 9, Name = "Crusader" },
                new Car() { Id = 10, Name = "Road King" },
                new Car() { Id = 11, Name = "Banger" },
                new Car() { Id = 12, Name = "Bullet" },
                new Car() { Id = 13, Name = "Canyon" },
                new Car() { Id = 14, Name = "Mad Rash" },
                new Car() { Id = 15, Name = "Fortune" },
                new Car() { Id = 16, Name = "Shaker" },
                new Car() { Id = 17, Name = "Nevada" },
                new Car() { Id = 18, Name = "CTR" },
                new Car() { Id = 18, Name = "Insetta Sport" },
                new Car() { Id = 18, Name = "Splitter" },
            };
            foreach (Car car in cars) context.Cars.Add(car);

            /*
            Score[] scores = {
                new Score(1, circuits[3], cars[5], users[1], new DateTime(2013, 2, 28), new TimeSpan(0, 0, 0, 51, 99)),
                new Score(2, circuits[7], cars[3], users[0], new DateTime(2013, 3, 13), new TimeSpan(0, 0, 1, 4, 22)),
            };
            foreach (Score score in scores) context.Scores.Add(score);
            */
        }
    }
}